<template>
  <section class="category-section">
    <h3 class="title">
      <span class="text">{{ title }}</span>
    </h3>

    <div class="product-container">
      <!-- 自定义轮播图 -->
      <div class="carousel">
        <!-- 轮播控制按钮 -->
        <button class="carousel-arrow prev" @click="prevSlide" aria-label="Previous slide">
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M15 19L8 12L15 5" stroke="currentColor" stroke-width="2" stroke-linecap="round"
              stroke-linejoin="round" />
          </svg>
        </button>

        <div class="carousel-container">
          <div class="carousel-track" :style="carouselTrackStyle">
            <!-- 为实现无限轮播，在最前面添加最后一组产品的克隆 -->
            <div class="carousel-slide" v-if="productGroups.length > 0" :key="'clone-last'">
              <div class="product-card" v-for="product in productGroups[productGroups.length - 1]"
                :key="`clone-${product.id}`">
                <div class="product-image-container">
                  <span v-if="product.badge" class="badge">{{ product.badge }}</span>
                  <div class="product-image-wrapper">
                    <a :href="`/product/${product.url}.html`" target="_self" :title="product.name">
                      <img :src="product.image" :alt="product.title" class="product-image main-image">
                      <img :src="product.hoverImage" :alt="`${product.title} Hover`" class="product-image hover-image">
                      <button class="wishlist-btn" @click.prevent="toggleWishlist(product)">
                        <div class="wishlist-tooltip">
                          <span v-if="product.isWishlist === 0">Add To Wishlist</span>
                          <span v-else>Added To Wishlist</span>
                        </div>
                        <svg width="22" height="22" viewBox="0 0 26 26" fill="none" xmlns="http://www.w3.org/2000/svg">
                          <path
                            d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
                            :stroke="product.isWishlist === 1 ? 'none' : 'currentColor'"
                            :fill="product.isWishlist === 1 ? '#000' : 'none'" stroke-width="2" />
                        </svg>
                      </button>
                    </a>
                  </div>
                  <div class="product-actions">
                    <button class="add-to-cart-btn" @click.prevent.stop="addToCart(product)">ADD TO CART</button>
                  </div>
                </div>
                <div class="product-info">
                  <h3 class="product-title">{{ product.title }}</h3>
                  <p class="product-price">{{ useCurrency.currentCurrency.unit }} {{
                    globalProperties?.$ConvertPrice(product.price) }}<span class="zk-price">{{
                      useCurrency.currentCurrency.unit }} {{
                        globalProperties?.$ConvertPrice(product.origin_price) }}</span></p>
                </div>
              </div>
            </div>

            <!-- 正常的轮播内容 -->
            <div class="carousel-slide" v-for="(group, groupIndex) in productGroups" :key="groupIndex">
              <div class="product-card" v-for="product in group" :key="product.id">
                <div class="product-image-container">
                  <span v-if="product.badge" class="badge">{{ product.badge }}</span>
                  <div class="product-image-wrapper">
                    <a :href="`/product/${product.url}.html`" target="_self" :title="product.name">
                      <img :src="product.image" :alt="product.title" class="product-image main-image">
                      <img :src="product.hoverImage" :alt="`${product.title} Hover`" class="product-image hover-image">
                      <button class="wishlist-btn" @click.prevent="toggleWishlist(product)">
                        <div class="wishlist-tooltip">
                          <span v-if="product.isWishlist === 0">Add To Wishlist</span>
                          <span v-else>Added To Wishlist</span>
                        </div>
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                          <path
                            d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
                            :stroke="product.isWishlist === 1 ? 'none' : 'currentColor'"
                            :fill="product.isWishlist === 1 ? '#000' : 'none'" stroke-width="2" />
                        </svg>
                      </button>
                    </a>
                  </div>
                  <div class="product-actions">
                    <button class="add-to-cart-btn" @click.prevent.stop="addToCart(product)">ADD TO CART</button>
                  </div>
                </div>
                <div class="product-info">
                  <h3 class="product-title">{{ product.title }}</h3>
                  <p class="product-price">{{ useCurrency.currentCurrency.unit }} {{
                    globalProperties?.$ConvertPrice(product.price) }}<span class="zk-price">{{
                      useCurrency.currentCurrency.unit }} {{
                        globalProperties?.$ConvertPrice(product.origin_price) }}</span></p>
                </div>
              </div>
            </div>

            <!-- 为实现无限轮播，在最后添加第一组产品的克隆 -->
            <div class="carousel-slide" v-if="productGroups.length > 0" :key="'clone-first'">
              <div class="product-card" v-for="product in productGroups[0]" :key="`clone-${product.id}`">
                <div class="product-image-container">
                  <span v-if="product.badge" class="badge">{{ product.badge }}</span>
                  <div class="product-image-wrapper">
                    <a :href="`/product/${product.url}.html`" target="_self" :title="product.name">
                      <img :src="product.image" :alt="product.title" class="product-image main-image">
                      <img :src="product.hoverImage" :alt="`${product.title} Hover`" class="product-image hover-image">
                      <button class="wishlist-btn" @click.prevent="toggleWishlist(product)">
                        <div class="wishlist-tooltip">
                          <span v-if="product.isWishlist === 0">Add To Wishlist</span>
                          <span v-else>Added To Wishlist</span>
                        </div>
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                          <path
                            d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
                            :stroke="product.isWishlist === 1 ? 'none' : 'currentColor'"
                            :fill="product.isWishlist === 1 ? '#000' : 'none'" stroke-width="2" />
                        </svg>
                      </button>
                    </a>
                  </div>
                  <div class="product-actions">
                    <button class="add-to-cart-btn" @click.prevent.stop="addToCart(product)">ADD TO CART</button>
                  </div>
                </div>
                <div class="product-info">
                  <h3 class="product-title">{{ product.title }}</h3>
                  <p class="product-price">{{ useCurrency.currentCurrency.unit }} {{
                    globalProperties?.$ConvertPrice(product.price) }}<span class="zk-price">{{
                      useCurrency.currentCurrency.unit }} {{
                        globalProperties?.$ConvertPrice(product.origin_price) }}</span></p>
                </div>
              </div>
            </div>
          </div>
        </div>

        <button class="carousel-arrow next" @click="nextSlide" aria-label="Next slide">
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M9 5L16 12L9 19" stroke="currentColor" stroke-width="2" stroke-linecap="round"
              stroke-linejoin="round" />
          </svg>
        </button>
      </div>

      <!-- 轮播指示器 -->
      <div class="carousel-indicators">
        <button v-for="(_, index) in productGroups" :key="index" :class="['indicator', { active: realIndex === index }]"
          @click="goToSlide(index)" :aria-label="`Go to slide ${index + 1}`"></button>
      </div>

      <!-- <div class="shop-now"> 
        <a href="/products">SHOP NOW</a>
      </div> -->
    </div>
  </section>
  <a-modal v-model:open="open" width="1260px" title="Product Details" :footer="null">
    <ProductDetail.default v-if="open && goodId" :goodId="goodId" @buy="handleBuy" />
  </a-modal>
</template>

<script lang="ts" setup>
import { ref, reactive, computed, onMounted, onBeforeUnmount, watch, getCurrentInstance, type ComponentInternalInstance } from 'vue';
import { message } from 'ant-design-vue';
import * as ProductDetail from '@/components/ProductDetail.vue';
import { useCartStore } from '@/store/cart';
import mitt from '@/utils/mitt';
// @ts-ignore
import { addFavorite, deleteFavorite } from "@/api/goods";
// @ts-ignore
import { useCurrencyStore } from '@/store'
import { Session } from '@/utils/storage';
import { getToken } from '@/utils/auth';
import { useRouter } from 'vue-router';
// 定义产品接口
interface Product {
  id: number;
  title: string;
  price: number;
  image: string;
  hoverImage: string;
  badge?: string;
  isWishlist: number;
  inventory: number;
}

// 定义标签页接口
interface Tab {
  name: string;
  id: string;
  isActive: boolean;
}
const router = useRouter();
const cartStore = useCartStore()
// 获取组件实例
const instance = getCurrentInstance();
// 获取全局属性和转换价格方法
const globalProperties = instance ? (instance as any).proxy : null;
const useCurrency = useCurrencyStore()

const props = defineProps({
  // 表单初始数据
  options: {
    type: Object,
    default: () => ({
      id: 1,
      title: '',
      price: 0,
      image: '',
      hoverImage: '',
      badge: '',
      isWishlist: 0,
      inventory: 0
    })
  },
  title: {
    type: String,
    default: ''
  }
});

// 定义标签页数据
const tabs = reactive<Tab[]>([
  {
    name: 'BEST SELLERS',
    id: 'best-sellers',
    isActive: true
  },
  {
    name: 'NEW ARRIVALS',
    id: 'new-arrivals',
    isActive: false
  },
  {
    name: 'LINEN',
    id: 'linen',
    isActive: false
  }
]);

// 当前激活的标签索引
const activeTabIndex = ref(0);

// // 所有分类的商品数据
// const allCategoryProducts = reactive<Record<string, Product[]>>({
//   'best-sellers': [
//     {
//       id: 1,
//       title: '100% Linen Vest And Pants Two-Piece Set',
//       price: 159,
//       image: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/a9cd27cd1bb38dfdd3b08c3c3f4ea164.jpg?v=1744851115',
//       hoverImage: 'https://cdn.shopify.com/s/files/1/0617/0099/7296/files/56fc64f0dc9697b81dd89d04afd03e9e.jpg?v=1745736279',
//       badge: 'Best Seller',
//       isWishlist: false,
//       inventory: 10
//     },
//   ]
// });

// // 当前显示的商品数据
// const currentProducts = ref(allCategoryProducts[tabs[0].id]);

// 选择标签页
const selectTab = (index: number) => {
  if (activeTabIndex.value === index) return;

  activeTabIndex.value = index;
  // currentProducts.value = allCategoryProducts[tabs[index].id];

  // 重置轮播位置
  currentSlide.value = 1;
  isTransitioning.value = false;

  // 重新开始自动播放
  resetAutoplay();

  // 可以在这里添加分析事件追踪
  console.log(`Tab changed to: ${tabs[index].name}`);
};

// 定义产品数据
const products = ref<Product[]>([]);

// 使用计算属性来决定显示初始数据还是当前选择的分类数据
const displayProducts = computed(() => {
  // 如果有传入的选项数据，优先使用
  if (Array.isArray(props.options) && props.options.length > 0) {
    return props.options;
  }
  // 否则使用当前标签选择的数据
  // return currentProducts.value;
});

// 轮播相关状态
const currentSlide = ref(1); // 从1开始，因为0是克隆的最后一组
const isTransitioning = ref(false);
const itemsPerGroup = ref(4); // 每组显示4个产品
let autoplayInterval = ref<number | null>(null);

// 真实的轮播索引（用于指示器显示）
const realIndex = computed(() => {
  if (currentSlide.value === 0) {
    return productGroups.value.length - 1;
  } else if (currentSlide.value === productGroups.value.length + 1) {
    return 0;
  } else {
    return currentSlide.value - 1;
  }
});

// 轮播轨道样式
const carouselTrackStyle = computed(() => {
  return {
    transform: `translateX(-${currentSlide.value * 100}%)`,
    transition: isTransitioning.value ? 'transform 0.5s ease' : 'none'
  };
});

// 计算分组后的产品数据
const productGroups = computed(() => {
  const groups = [];
  const productsArray = [...displayProducts.value]; // 使用displayProducts计算属性

  // 获取收藏列表并且设置是否收藏isWishlist
  let collectList = Session.get('collectList');
  if (collectList) {
    productsArray.forEach(item => {
      collectList.forEach((collect: any) => {
        if (collect.goods_id === item.id) {
          item.isWishlist = 1
        }
      });
    });
  }

  for (let i = 0; i < productsArray.length; i += itemsPerGroup.value) {
    groups.push(productsArray.slice(i, i + itemsPerGroup.value));
  }

  return groups;
});

// 轮播控制函数
const nextSlide = () => {
  if (isTransitioning.value) return;

  isTransitioning.value = true;
  currentSlide.value++;

  resetAutoplay();

  // 如果到了最后一个克隆元素，等待过渡结束后，无缝切换到真实的第一个元素
  if (currentSlide.value === productGroups.value.length + 1) {
    setTimeout(() => {
      isTransitioning.value = false;
      currentSlide.value = 1;
    }, 5000);
  } else {
    setTimeout(() => {
      isTransitioning.value = false;
    }, 500);
  }
};

const prevSlide = () => {
  if (isTransitioning.value) return;

  isTransitioning.value = true;
  currentSlide.value--;

  resetAutoplay();

  // 如果到了第一个克隆元素，等待过渡结束后，无缝切换到真实的最后一个元素
  if (currentSlide.value === 0) {
    setTimeout(() => {
      isTransitioning.value = false;
      currentSlide.value = productGroups.value.length;
    }, 500);
  } else {
    setTimeout(() => {
      isTransitioning.value = false;
    }, 500);
  }
};

const goToSlide = (index: number) => {
  if (isTransitioning.value) return;

  isTransitioning.value = true;
  currentSlide.value = index + 1; // +1 因为索引0是克隆的最后一组

  resetAutoplay();

  setTimeout(() => {
    isTransitioning.value = false;
  }, 500);
};

// 自动播放控制
const startAutoplay = () => {
  stopAutoplay();
  autoplayInterval.value = window.setInterval(() => {
    nextSlide();
  }, 10000); // 5秒切换一次
};

const stopAutoplay = () => {
  if (autoplayInterval.value) {
    clearInterval(autoplayInterval.value);
    autoplayInterval.value = null;
  }
};

const resetAutoplay = () => {
  if (autoplayInterval.value) {
    startAutoplay();
  }
};
const isLogin = ref(!!getToken());;
// 添加到收藏
const toggleWishlist = async (product: Product): void => {
  if (!isLogin.value) {
    message.error('Please log in first.');
    setTimeout(() => {
      router.push('/login');
    }, 1500);
    return;
  }

  try {
    const res = product.isWishlist === 1
      ? await deleteFavorite(String(product.id))
      : await addFavorite(String(product.id));

    if (res.code === 200) {
      if (product.isWishlist === 1) {
        product.isWishlist = 0
      } else {
        product.isWishlist = 1
      }
    }

    // 显示成功消息
    const action = product.isWishlist === 1 ? 'added to' : 'removed from';
    message.success(`Item ${action} wishlist successfully`);

    // 更新本地存储中的收藏列表
    if (product.isWishlist === 1) {
      // 如果添加收藏，可以在这里更新本地收藏列表
      let collectData = cartStore.getCollect?.() || [];

      // 添加到收藏列表
      if (Array.isArray(collectData)) {
        // 确保不重复添加
        if (!collectData.some((item: any) => item.goods_id === product.id)) {
          collectData.push({ goods_id: product.id });
        }
      }else{
        collectData = [{ goods_id: product.id }];
      }
      cartStore.setCollect?.(collectData);
    } else {
      // 如果取消收藏，从本地列表中移除
      let collectData = cartStore.getCollect?.();
      if (collectData) {
        collectData = collectData.filter((item: any) => item.goods_id !== product.id);
        cartStore.setCollect?.(collectData);
      }
      
    }
  } catch (error) {
    console.error('Failed to update favorite status:', error);
  }
};

const open = ref<boolean>(false);
// 修改goodId类型为string，允许null
const goodId = ref<string | null>(null);
// 添加到购物车
const addToCart = (product: Product) => {
  console.log('Added to cart:', product);
  if (!isLogin.value) {
    message.error('Please log in first.');
    setTimeout(() => {
      router.push('/login');
    }, 1500);
    return;
  }
  open.value = true;
  goodId.value = String(product.id); // 将数字ID转换为字符串
}

const handleBuy = (product: any) => {
  // message.success('The product has been successfully added to the cart');
  open.value = false;
};

// 窗口大小调整处理
const updateItemsPerGroup = () => {
  const width = window.innerWidth;
  if (width <= 480) {
    itemsPerGroup.value = 1;
  } else if (width <= 768) {
    itemsPerGroup.value = 2;
  } else if (width <= 1024) {
    itemsPerGroup.value = 3;
  } else {
    itemsPerGroup.value = 4;
  }
};

// 生命周期钩子
onMounted(() => {
  updateItemsPerGroup();
  window.addEventListener('resize', updateItemsPerGroup);
  // startAutoplay();

  // 初始化时确保不显示过渡效果
  isTransitioning.value = false;
});

onBeforeUnmount(() => {
  window.removeEventListener('resize', updateItemsPerGroup);
  stopAutoplay();
});

// 暴露组件内部方法和数据
defineExpose({
  products,
  // tabs,
  currentSlide,
  nextSlide,
  prevSlide,
  goToSlide
});
</script>

<style scoped lang="scss">
// 分类区域样式
.category-section {
  margin-bottom: 80px;
  margin-top: 110px;
  width: 100%;
  background-color: #fff;
}

.title {
  font-size: 26px;
  text-align: center;
  color: #232323;
  margin-bottom: 40px;
}

.category-tabs {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}

.tab-container {
  display: flex;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 10px;
}

.tab-item {
  font-size: 16px;
  font-weight: 500;
  color: #6c6c6c;
  padding: 0 20px;
  position: relative;
  text-decoration: none;
  letter-spacing: 1px;
  cursor: pointer;
}

.tab-item.active {
  color: #000;
  font-weight: 600;
}

.tab-item.active:after {
  content: '';
  position: absolute;
  bottom: -11px;
  left: 20px;
  right: 20px;
  height: 2px;
  background-color: #000;
}

.product-container {
  margin: 0 auto;
  padding: 0 15px;
  position: relative;
}

// 轮播图样式
.carousel {
  position: relative;
  width: 100%;
  overflow: hidden;
  margin-bottom: 30px;
  display: flex;
  align-items: center;
}

.carousel-container {
  width: 100%;
  overflow: hidden;
}

.carousel-track {
  display: flex;
  transition: transform 0.5s ease;
  will-change: transform;
}

.carousel-slide {
  flex: 0 0 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 25px;
}

.carousel-arrow {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.8);
  border: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  top: calc((133% / 2) - 140px);
  /* 图片高度的一半，基于padding-bottom: 133% */
  transform: translateY(-50%);

  &:hover {
    background-color: rgba(249, 241, 238, 0.9);
    transform: translateY(-50%) scale(1.05);
  }

  &.prev {
    left: 15px;
  }

  &.next {
    right: 15px;
  }

  svg {
    width: 20px;
    height: 20px;
    color: #333;
  }
}

// 指示器样式
.carousel-indicators {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  gap: 8px;
}

.indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #ccc;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: all 0.3s ease;

  &.active {
    background-color: #d7b8a9;
    transform: scale(1.2);
  }
}

.product-card {
  position: relative;
  overflow: hidden;
  background-color: #fff;
}

.product-card:hover {
  transform: none;
  box-shadow: none;
}

.product-image-container {
  position: relative;
  width: 100%;
  padding-bottom: 133%;
  /* 3:4 aspect ratio */
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product-image-container:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.05);
}

.badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: rgb(215, 184, 169);
  color: #fff;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 2px;
  z-index: 2;
}

.product-image-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.product-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.5s ease;
}

.main-image {
  opacity: 1;
}

.hover-image {
  opacity: 0;
}

.product-image-container:hover .main-image {
  opacity: 0;
}

.product-image-container:hover .hover-image {
  opacity: 1;
}

.product-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transform: translateY(0);
  transition: opacity 0.3s ease;
  z-index: 3;
  width: 100%;
}

.product-image-container:hover .product-actions {
  opacity: 1;
}

.add-to-cart-btn {
  background-color: rgba(255, 255, 255, 0.9);
  color: #000;
  border: 1px solid #000;
  // padding: 12px 0;
  height: 40px;
  line-height: 40px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0;
  letter-spacing: 1px;
  width: 100%;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.add-to-cart-btn:hover {
  background-color: #000;
  color: #fff;
}

.wishlist-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background-color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s ease;
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.3s ease;

  svg {
    position: absolute;
    z-index: 4;
  }

  .wishlist-tooltip {
    position: absolute;
    top: 0;
    right: 18px;
    z-index: 3;
    background-color: white;
    color: #000;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 20px 0 0 20px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    font-weight: normal;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    overflow: hidden;
    max-width: 0;
    transform-origin: right center;

    span {
      padding: 0 12px;
      opacity: 0;
      transition: opacity 0.2s ease 0.1s;
    }
  }

  &:hover {
    .wishlist-tooltip {
      max-width: 150px;
      opacity: 1;
      padding: 0 10px 0 0;

      span {
        opacity: 1;
      }
    }
  }
}

.product-image-container:hover .wishlist-btn {
  opacity: 1;
}

.product-info {
  padding-top: 15px;
}

.product-title {
  font-size: 14px;
  color: #232323;
  ;
  margin-bottom: 8px;
  font-weight: 400;
  line-height: 1.4;
}

.product-price {
  font-size: 14px;
  color: #000;
  font-weight: 500;

  .zk-price {
    text-decoration: line-through;
    margin-left: 6px;
    color: #999;
    font-weight: normal;
    font-size: 90%;
  }
}

/* 移动端适配 */
@media (max-width: 1024px) {
  .carousel-slide {
    grid-template-columns: repeat(3, 1fr);
  }

  .carousel-arrow {
    width: 36px;
    height: 36px;

    &:hover {
      transform: translateY(-50%) scale(1.05);
    }

    svg {
      width: 18px;
      height: 18px;
    }
  }
}

@media (max-width: 768px) {
  .carousel-slide {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }

  .tab-item {
    font-size: 14px;
    padding: 0 15px;
  }

  .product-actions {
    opacity: 1;
  }

  .add-to-cart-btn {
    padding: 10px 0;
    font-size: 11px;
  }

  .wishlist-btn {
    opacity: 1;
  }

  .carousel-arrow {
    width: 32px;
    height: 32px;

    &:hover {
      transform: translateY(-50%) scale(1.05);
    }

    svg {
      width: 16px;
      height: 16px;
    }
  }
}

@media (max-width: 480px) {
  .carousel-slide {
    grid-template-columns: 1fr;
  }

  .tab-container {
    width: 100%;
    justify-content: space-between;
  }

  .tab-item {
    padding: 0 10px;
    font-size: 12px;
  }

  .tab-item.active:after {
    left: 10px;
    right: 10px;
  }

  .product-title {
    font-size: 13px;
  }

  .product-price {
    font-size: 13px;
  }

  .badge {
    font-size: 10px;
    padding: 2px 8px;
  }

  .carousel-arrow {
    width: 28px;
    height: 28px;

    &:hover {
      transform: translateY(-50%) scale(1.05);
    }

    svg {
      width: 14px;
      height: 14px;
    }
  }

  .carousel-indicators {
    margin-top: 15px;
  }

  .indicator {
    width: 6px;
    height: 6px;
  }
}
</style>